package org.texteasy;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.View;
import android.widget.TextView;

public class WhatsNewDialog extends Activity {
	
	//Be sure to update the string for newer versions
	//maybe clean up older versions as well
	public static final String WHATS_NEW = "WHATS_NEW1.4";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		//requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		setTitle(R.string.WHATS_NEW_TITLE);
		setContentView(R.layout.whats_new);
		
		TextView view = (TextView)findViewById(R.id.ShowAllNumbers);
		SpannableString s = SpannableString.valueOf(getString(R.string.ShowAllNumbers));
		s.setSpan(new ClickableSpan(){
			@Override
			public void onClick(View widget) {
				startActivity(new Intent(WhatsNewDialog.this, TextEasyPreferences.class));
			}
			
		}, 157, 165, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
		
		s.setSpan(new ClickableSpan(){
			@Override
			public void onClick(View widget) {
				startActivity(new Intent(WhatsNewDialog.this, PhoneTypesPreferences.class));
			}
			
		}, 169, 189, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
		view.setText(s);
		view.setMovementMethod(LinkMovementMethod.getInstance());
		
		view = (TextView)findViewById(R.id.verizon);
		s = SpannableString.valueOf(getString(R.string.whatsnew_verizon));
		s.setSpan(new ClickableSpan(){
			@Override
			public void onClick(View widget) {
				startActivity(new Intent(WhatsNewDialog.this, TextEasyPreferences.class));
			}
			
		}, 114, 122, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
		view.setText(s);
		view.setMovementMethod(LinkMovementMethod.getInstance());
		
		view = (TextView)findViewById(R.id.performance_warning);
		String message = getString(R.string.whatsnew_performance);
		message = message.replace("${count}", WarningActivity.GENERAL_WARNING_COUNT + "");
		view.setText(message);
		
		view = (TextView)findViewById(R.id.whatsnew_phone_filter);
		s = SpannableString.valueOf(getString(R.string.whatsnew_phone_filter));
		s.setSpan(new ClickableSpan(){
			@Override
			public void onClick(View widget) {
				startActivity(new Intent(WhatsNewDialog.this, TextEasyPreferences.class));
			}
			
		}, 159, 167, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
		
		s.setSpan(new ClickableSpan(){
			@Override
			public void onClick(View widget) {
				startActivity(new Intent(WhatsNewDialog.this, PhoneTypesPreferences.class));
			}
			
		}, 171, 192, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
		view.setText(s);
		view.setMovementMethod(LinkMovementMethod.getInstance());
		
		findViewById(R.id.btn_close).setOnClickListener(new View.OnClickListener(){
			
			public void onClick(View v) {
				
				
				finish();
			}
		});
		
		SharedPreferences prefs = PreferenceManager
			.getDefaultSharedPreferences(WhatsNewDialog.this);
		if(!prefs.getBoolean(WHATS_NEW, false)){
			Editor editor = prefs.edit();
			editor.putBoolean(WHATS_NEW, true);
			editor.commit();
		}
	}
	
	
}
